package com.ybfenpan.service.center;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ybfenpan.model.Member;
import com.ybfenpan.model.center.RequestCenter;
import com.ybfenpan.service.MemberService;
import com.ybfenpan.service.core.BaseService;
import com.ybfenpan.utils.StringUtil;

@Service
public class RequestCenterService extends BaseService {

	@Resource
	private MemberService memberService;

	/**
	 * @功能 通过审核
	 */
	public void updateCommitOne(RequestCenter one) {

		Integer state = one.getState();
		if (state.equals(10)) {
			Member member = this.memberService.getByKey(one.getMemberId());
			if (member.getAccountCenter().equals("F")) {
				// 修改请求状态
				one.setState(20);
				one.setCommitDate(new Date());
				this.saveOrUpdate(one);
				// 修改自己为区域管理中心
				member.setCenterTitle(one.getTitle());
				member.setCenterAdds(one.getAddress());
				member.setHistoryBuyStock(one.getCenterLevel());
				member.setAccountCenter("T");
				memberService.update(member);
			}
		}
	}

	public RequestCenter executCenterByLoginName(String requestCenter) {
		if (StringUtil.isNotBlank(requestCenter)) {
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("title", requestCenter);
			List<RequestCenter> members = queryForList("select", param);
			if (null != members && 0 < members.size()) {
				return members.get(0);
			}
		}
		return null;
	}

}
